package com.nblog.interceptor.front;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.kit.StrKit;
import com.nblog.model.User;
import com.nblog.utils.IWebUtils;

public class LoginInterceptor implements Interceptor {
	@Override
	public void intercept(Invocation inv) {
		User user=IWebUtils.getCurrentSysUser(inv.getController().getRequest());
		System.out.println(user);
		if(user==null){
			if(StrKit.notBlank(inv.getActionKey())&&!inv.getActionKey().equals("/")){
				inv.getController().redirect("/auth/login?url="+inv.getActionKey());
			}else{
				inv.getController().redirect("/auth/login");
			}
		}else{
			inv.getController().setAttr("userinfo", user);
			inv.invoke();
		}
		
	}

}
